package com.wyix.controller;

import com.wyix.model.User;
import com.wyix.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author wangdx
 * @since 2025/8/8
 */
@Controller
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/{username}")
    public String getUser(@PathVariable String username, Model model) {
        User user = userService.getUserByUsername(username);
        if (user != null) {
            model.addAttribute("user", user);
            return "userProfile";
        } else {
            model.addAttribute("error", "用户不存在");
            return "error";
        }
    }
}
